package com.markedquilt.interedu.controller.wechat;

import com.markedquilt.interedu.enums.ErrorEnum;
import com.markedquilt.interedu.repository.domain.User;
import com.markedquilt.interedu.service.UserService;
import com.markedquilt.interedu.util.JsonUtil;
import com.markedquilt.interedu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZhangKe
 * @Description
 * @date 2020/3/29 23:47.
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/{id}")
    public Result getById(@PathVariable(value = "id") Integer id){
        try{
            User user=userService.getById(id);
            if (user!=null)
                return JsonUtil.success(user);
            else
                return JsonUtil.error(ErrorEnum.NO_USER);
        }catch(Exception e){
            return JsonUtil.error(ErrorEnum.NO_USER);
        }
    }
}
